﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using DigitalPlatform.Common.Mangaer;
using DigitalPlatform.Entities;
using DigitalPlatform.IDAL;
using DigitalPlatform.Models;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;

namespace DigitalPlatform.ViewModels.Pages
{
    public class MonitorPageViewModel : BindableBase
    {
        private readonly IDialogService _dialogservice;
        private readonly ILocalDataAccess _localDataAccess;

        public MonitorPageViewModel(IDialogService service, ILocalDataAccess localDataAccess)
        {
            this._dialogservice = service;
            this._localDataAccess = localDataAccess;
            init();

        }
        private void init()
        {
            #region cmdinit
            Cmd_ConfigEdit = new DelegateCommand(BN_ConfigEdit);
            #endregion

            GasList = new ObservableCollection<GasUseModel>();
            AlarmList = new ObservableCollection<AlarmModel>();
            GasList.Add(new GasUseModel { Name = "车间一", Plan = 120d, Actual = 60d });
            GasList.Add(new GasUseModel { Name = "车间二", Plan = 160d, Actual = 80d });
            GasList.Add(new GasUseModel { Name = "车间三", Plan = 180d, Actual = 40d });
            GasList.Add(new GasUseModel { Name = "车间四", Plan = 130d, Actual = 60d });
            GasList.Add(new GasUseModel { Name = "车间五", Plan = 130d, Actual = 67d });

            AlarmList.Add(new AlarmModel("AAA_1", "保养到期", DateTime.Now.ToString()));
            AlarmList.Add(new AlarmModel("AAA_2", "保养到期", DateTime.Now.ToString()));
            AlarmList.Add(new AlarmModel("AAA_3", "保养到期", DateTime.Now.ToString()));
            AlarmList.Add(new AlarmModel("AAA_4", "保养到期", DateTime.Now.ToString()));
            AlarmList.Add(new AlarmModel("AAA_5", "保养到期", DateTime.Now.ToString()));
            AlarmList.Add(new AlarmModel("AAA_6", "保养到期", DateTime.Now.ToString()));
        }
        #region func
        private async void BN_ConfigEdit()
        {
            //显示此窗口使用自定义的Window界面
            //_dialogservice.ShowDialog("ComponentConfigView",null,null, "DialogWindowBase"); 
            var result = ActionManager<bool>.ExecuteAction("ShowCompConfig");
            if (result)
            {
                var dev = await _localDataAccess.QueryEntities<DeviceEntity>();
                var ls = dev.Select(x => new DeviceItemModel()
                {
                    X = double.Parse(x.X),
                    Y = double.Parse(x.Y),
                    Z = int.Parse(x.Z),
                    DeviceType = x.DeviceTypeName,
                    DeviceNum = x.DeviceNum,
                    Height = double.Parse(x.W),
                    Width = double.Parse(x.H)
                });
                DeviceList = ls.ToList();
            }
        }
        #endregion 
        #region props

        private List<DeviceItemModel> _devList;

        public List<DeviceItemModel> DeviceList
        {
            get { return _devList; }
            set { SetProperty(ref _devList, value); }
        }
        public ObservableCollection<GasUseModel> GasList { get; set; }
        public ObservableCollection<AlarmModel> AlarmList { get; set; }
        #endregion
        #region cmd
        public ICommand Cmd_ConfigEdit { get; set; }
        #endregion
    }
}
